home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / frexxed / fpl / completeword.fpl < prev    next >
Text File  |  1996-01-17  |  3KB  |  91 lines

  1. // $Id: CompleteWord.FPL 1.8 1996/01/17 19:10:05 jskov Exp $
  2. // $VER: CompleteWord.FPL 1.3 (17.01.96) © Jesper Skov
  3.  
  4. int export WC_prevCall;
  5.  
  6. // Preserve for next call
  7. string WC_hitString, WC_orgWord, WC_Direction;
  8. int    WC_prevHitLine, WC_prevHitByte;
  9.  
  10. void export WordComplete()
  11. {
  12.   string searchString, tempString;
  13.   int searchResult;
  14.   int byte, line;
  15.   int currentID = GetEntryID();
  16.  
  17.   Visible(0);
  18.   if ((ReadInfo("counter")!=(WC_prevCall+1))){
  19.     // First entry
  20.     Output(" "); // So in-word completion may be made
  21.     if (strlen(WC_orgWord = GetWord(-1,ReadInfo("byte_position")-2))){
  22.       // string not empty - init data
  23.       WC_hitString = "*"+WC_orgWord+"*";
  24.       WC_prevHitLine = ReadInfo("line");
  25.       WC_prevHitByte = ReadInfo("byte_position")-1;
  26.       WC_Direction = "";                    // start searching backwards
  27.     } else {
  28.       Backspace();                            // fix space from above
  29.       Visible(1);
  30.       ReturnStatus("No word to complete!");
  31.       exit;
  32.     }
  33.   }
  34.  
  35.   BackspaceWord();
  36.  
  37.   byte = ReadInfo("byte_position")-1;
  38.   line = ReadInfo("line");
  39.  
  40.   CurrentBuffer(WC_prevCall = DuplicateEntry());
  41.   // internal use of WC_prevCall - search buffer ID. Exported var needed in clean kill below
  42.  
  43.   GotoLine(WC_prevHitLine, WC_prevHitByte);
  44.  
  45.   searchString = joinstr("\\<", WC_orgWord);
  46.  
  47.   do {
  48.     searchResult = Search(searchString, joinstr("=w", WC_Direction, "+"), ReadInfo("size"));
  49.     if (searchResult == -9){
  50.       // not found in this direction
  51.       if (strlen(WC_Direction) == 0){
  52.         // try searching down
  53.         WC_Direction = "f";
  54.         GotoLine(line, byte);
  55.       } else {
  56.         // not found at all...
  57.         ReturnStatus("Not found!");
  58.         searchResult = 0;
  59.         CurrentBuffer(currentID);
  60.         Clean("Kill(WC_prevCall);");
  61.         Output(WC_orgWord);                    // re-insert org word
  62.         Visible(1);
  63.         exit;
  64.         // WC_pC not updated, thus no problems at next call - will reset
  65.       }
  66.     } else {                                // Yeah, we struck metal
  67.       tempString = GetWord();
  68.       if (stristr(WC_hitString, joinstr("*",tempString,"*"))==-1){
  69.         // Did not appear in hitString! This is gold!
  70.         WC_prevHitLine = ReadInfo("line");
  71.         WC_prevHitByte = ReadInfo("byte")-1;
  72.         WC_hitString = joinstr(WC_hitString, tempString, "*");
  73.         CurrentBuffer(currentID);
  74.         Clean("Kill(WC_prevCall);");
  75.         Output(tempString);
  76.         Visible(1);
  77.         RedrawScreen();
  78.       } else {
  79.         // User already canned this word... Try again
  80.         searchResult = 1;
  81.       }
  82.     }
  83.  
  84.   } while (searchResult != 0);
  85.  
  86.   WC_prevCall=ReadInfo("counter");
  87. }         
  88.  
  89. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Key binding ««
  90. AssignKey("WordComplete();", "amiga /");
  91.